package com.example.applets;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyBatisCode {
    public static void main(String[] args) {
        //构建代码生成的对象
        AutoGenerator mpg = new AutoGenerator();
        //全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("云烟成雨丶");//作者
        gc.setOpen(false);
        gc.setFileOverride(false);//是否覆盖
        gc.setServiceName("%sService");//去掉Service的I前缀
        gc.setSwagger2(true); //实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        //设置数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/mytest?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("zzq11475@");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        //配置自动生成的包
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("Kshop");//模块名称
        pc.setParent("com.example");//包名
        pc.setEntity("entity");//实体类包名
        pc.setMapper("mapper");//mappar包名
        pc.setService("service");//业务层包名
        pc.setController("controller");//控制层包名
        mpg.setPackageInfo(pc);

        //策略设置
        StrategyConfig strategy = new StrategyConfig();
        String[] table = {"w_address", "w_admin", "w_carousel", "w_cart", "w_collect", "w_comment", "w_loginfo", "w_logistics", "w_menu", "w_menupriv", "w_order", "w_product", "w_role", "w_type", "w_user"};
        strategy.setInclude(table);//数据库表名
        strategy.setTablePrefix("w_");//去掉前缀
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);//自动生成lombok
        //strategy.setRestControllerStyle(true);//开启驼峰命名
        mpg.setStrategy(strategy);


        mpg.execute();


    }
}
